package com.aivin.web;

import com.aivin.entity.PicGroupWithPeopAndLikeInfoBean;
import com.aivin.entity.TbPic;
import com.aivin.pointsApi.CreditTool;
import com.aivin.pointsApi.MyConfig;
import com.aivin.service.PicService;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Controller//
@RequestMapping("/*")//
public class HomeController extends MultiActionController {
    @Autowired
    private PicService picService  ;

    /***
     *
     * http://localhost:8081/findYou/
     * user visit the website index page
     * @param model
     * @return
     */
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String index( Model model    ) {
        //获取列表页
        List<TbPic> list = null;
        int offset =0 ;
        int limit =  10 ;
        list = picService.getAllPicFy(offset  , limit) ;
        String jsonStr = JSON.toJSONString(list);
        model.addAttribute("jsonStr" ,jsonStr) ;
        System.out.println("默认首页###########"+list.size() );
        return "index";
    }





    /**
     * http://localhost:8081/findYou/indexWithParame
     *
     * */
    @RequestMapping(value = "/indexWithParame",
            method = {RequestMethod.POST},
            produces = "text/html;charset=UTF-8"
    )
    @ResponseBody
    public String  indexWithParame (@RequestParam("offset") int offset , @RequestParam("limit") int limit    ){
        List<TbPic> list = null;

        System.out.println("首页分页数据#################   offset="+ offset + " limit="+limit);
        list = picService.getAllPicFy(offset  , limit) ;
        String jsonStr = JSON.toJSONString(list);
        System.out.println(list.size()+  "  222jsonStr=\n"+ jsonStr  );

        return jsonStr;
    }






    //end test data
    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public String index2( Model model) {
        return "index";
    }

//    @RequestMapping(value = "/search", method = RequestMethod.GET)
//    public String search( Model model) {
//        return "search";
//    }

}